package com.iweb.servlet;

import org.apache.log4j.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @autor jay
 * @data 2020/12/16
 * @desc
 */
public class HelloServlet extends HttpServlet {
    private static final Logger logger = Logger.getLogger(HelloServlet.class);
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        logger.debug("执行了doGet()方法。。。");
        // 处理客户端的get请求
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        // 输出html元素与内容
        out.println("<html>");
        out.println("  <head><title>Servlet</title></head>");
        out.println("  <body>");
        out.println("你好，欢迎来到Servlet世界");
        out.println("  </body>");
        out.println("</html>");
        out.close();
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        logger.debug("执行了doPost()方法。。。");
        req.setCharacterEncoding("utf-8");
        this.doGet(req,resp);
    }
}
